package ai.mspbots.poc.controller.v2;

import ai.mspbots.poc.core.Response;
import ai.mspbots.poc.db.entity.AbbreviationMap;
import ai.mspbots.poc.db.service.AbbreviationMapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/v2/mapping")
public class MappingV2Controller {

    @Autowired
    private AbbreviationMapService abbreviationMapService;

    @GetMapping("/list")
    public Response<List<AbbreviationMap>> list() {
        return Response.success(abbreviationMapService.list());
    }

    @PostMapping("/create")
    public Response<Void> create(@RequestBody AbbreviationMap abbreviationMap) {
        abbreviationMapService.save(abbreviationMap);
        return Response.ok("创建完成");
    }

    @PostMapping("/remove")
    public Response<Void> remove(@RequestBody AbbreviationMap abbreviationMap) {
        abbreviationMapService.removeById(abbreviationMap.getId());
        return Response.ok("删除完成");
    }

    @PostMapping("/update")
    public Response<AbbreviationMap> update(@RequestBody AbbreviationMap abbreviationMap) {
        abbreviationMapService.updateById(abbreviationMap);
        return Response.success(abbreviationMapService.getById(abbreviationMap.getId()));
    }
}
